package com.czxy.service.impl;

import com.czxy.dao.CommodityDao;
import com.czxy.domain.Commodity;
import com.czxy.domain.CommodityVo;
import com.czxy.service.CommodityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangmengxiang1@itcast.cn
 * @version 1.0
 * @date 2020/2/11
 */
@Service
public class Commodityimpl implements CommodityService {

    @Resource
    private CommodityDao commodityDao;


    @Override
    public PageInfo<Commodity> findAllCommodity(CommodityVo commodityVo) {
        PageHelper.startPage(commodityVo.getPageNum(),commodityVo.getPageSize());
        List<Commodity> commodities = commodityDao.selectAll();
        return new PageInfo<>(commodities);
    }

    @Override
    public PageInfo<Commodity> findAllCommodityQS(CommodityVo commodityVo) {
        PageHelper.startPage(commodityVo.getPageNum(),commodityVo.getPageSize());
        List<Commodity> commodities = commodityDao.findAllCommodityQS();
        return new PageInfo<>(commodities);
    }

    @Override
    public Commodity checkoutBycid(Integer cid) {
        return commodityDao.selectByPrimaryKey(cid);
    }

    @Override
    public void updateCommodity(Commodity commodity) {
        commodityDao.updateByPrimaryKeySelective(commodity);
    }

    @Override
    public void updateCommodityNumber(Integer cid) {
        Commodity commodity = commodityDao.selectByPrimaryKey(cid);
        commodity.setCnumber(commodity.getCnumber()+100);
        commodityDao.updateByPrimaryKeySelective(commodity);
    }
}
